package 栈.练习;
//使用栈，逆序打印链表
import java.util.Stack;

class ListNode{
    int val;
    ListNode prev;
    ListNode next;

    public ListNode(int val) {
        this.val = val;
    }
}
public class Text_2  {
    public static ListNode head;
    public static void reverseDisplay(ListNode head){
        Stack<ListNode> stack =new Stack<>();
        ListNode cur = head;
//        放入栈
        while(cur!=null){
            stack.push(cur);
            cur  = cur.next;
        }

//        取出
        while(!stack.empty()){
            ListNode x = stack.pop();
            System.out.print(x.val+" ");
        }
        System.out.println();
    }

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 =new ListNode(3);
        listNode.next = listNode1;
        listNode1.next =listNode2;
        head = listNode;
        reverseDisplay(head);


    }

}
